using System.Web.Routing;
using FubuMVC.Core.Runtime;
using FubuMVC.StructureMap;
using StructureMap;

namespace Fubu.HelloWorld2
{
	public class FubuStructureMapBootstrapper : IBootstrapper {
		private readonly RouteCollection _routes;

		private FubuStructureMapBootstrapper(RouteCollection routes) {
			_routes = routes;
		}

		public void BootstrapStructureMap() {
			UrlContext.Reset();

			ObjectFactory.Initialize(x => { });

			BootstrapFubu(ObjectFactory.Container, _routes);
		}

		public static void BootstrapFubu(IContainer container, RouteCollection routes) {
			var bootstrapper = new StructureMapBootstrapper(container, new HelloWorldFubuRegistry());
			bootstrapper.Bootstrap(routes);
		}

		public static void Bootstrap(RouteCollection routes) {
			new FubuStructureMapBootstrapper(routes).BootstrapStructureMap();
		}
	}
}